package zfbxcx;

import android.app.Activity;
import android.util.Log;

import androidx.annotation.NonNull;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

public class ZhiFuBaoXCXPlugin implements MethodChannel.MethodCallHandler, FlutterPlugin {
    public static final String CHANNEL = "com.ahj/mPaasPlugin";
    static MethodChannel channe;
    public static Activity activity;
    public static MethodChannel.Result result;
    public static FlutterEngine fe;

    public ZhiFuBaoXCXPlugin(Activity activity) {
        this.activity = activity;
    }

    public static void registerWith(FlutterEngine flutterEngine, Activity activity12) {
        fe = flutterEngine;
        channe = new MethodChannel(flutterEngine.getDartExecutor(), CHANNEL);
        ZhiFuBaoXCXPlugin plugin = new ZhiFuBaoXCXPlugin(activity12);
        channe.setMethodCallHandler(plugin);
    }


    @Override
    public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
        try {


            if (methodCall.method.equals("jumpTomPaas")) {//跳转支付宝小程序
                Log.e("ssssssssssssss", "-------------------------------");

                String path = methodCall.argument("url");
                String page = methodCall.argument("page");
                String sid = methodCall.argument("sid");
                List<Map<String, Object>> data = methodCall.argument("data");

                String queryData = "";
//
//                for (int i = 0; i < data.size(); i++) {
//                    Map<String, Object> map = data.get(i);
//
//                    for (Map.Entry<String, Object> en : map.entrySet()) {
//
//                        if (en.getValue() != null && !"null".equalsIgnoreCase(en.getValue().toString())) {
//                            if (TextUtils.isEmpty(queryData)) {
//                                queryData = en.getKey() + "=" + en.getValue().toString();
//                            } else {
//                                queryData = queryData + "&" + en.getKey() + "=" + en.getValue().toString();
//                            }
//                        }
//
//                        if ("userId".equals(en.getKey())) {
//                            MPLogger.setUserId(en.getValue().toString());
//                        }
//                    }
//                }
//                Bundle bundle = new Bundle();
//                bundle.putString("page", page);
//                bundle.putString("query", queryData);
//                MPNebula.startApp(path, bundle);


//                MPFramework.getExternalService(H5Service.class.getName());
//                H5Session h5Session = h5Service.getTopSession();
//                h5Session.exitSession();

            }

        } catch (Exception e) {
            e.printStackTrace();
            result.success("");
        }
    }

    @Override
    public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {

    }

    @Override
    public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {

    }
}
